package com.lywz.web.action.upload;

import java.io.File;
import java.util.Collections;
import java.util.List;

import com.lywz.core.exception.SSException;
import com.lywz.core.fileUpload.UploadFile;
import com.lywz.core.log.LogClerk;
import com.lywz.web.struts.GZAbstracterAction;

/**
 * 保存文件
 * 
 * @author Lionel pang
 * @date 2010-4-19
 */
public class FileUpload extends GZAbstracterAction {

    private static final long serialVersionUID = -2180698971940763175L;

    private File upload;

    private String uploadFileName;

    public void save() {
        LogClerk.sysout.info("upload success" + upload.getName());

               UploadFile files = new UploadFile(upload, "aaa/", uploadFileName, 50, 50, request);
                /*files.setFile(upload);
                files.setPath("aaa/");
                files.setHeight(50);
                files.setWidth(50);
//                files.setBasePath(request.getRealPath("/") + "resource/");
                files.setProtypeFileName(uploadFileName);*/

                List<String> list = Collections.emptyList();
                try {
                    list = defaultFileUpload.uploadFile(files);
                } catch (SSException e) {
                    e.printStackTrace();
                }

                if (list.size() > 0) {
                    this.print(list.get(0));
                }
        
        print(request.getRealPath("/"));
    }

    public String home() {
        return "home";
    }
    /////////////////////////// getter and setter ///////////////
    
    public File getUpload() {
        return upload;
    }

    
    public void setUpload(File upload) {
        this.upload = upload;
    }

    
    public void setUploadFileName(String uploadFileName) {
        this.uploadFileName = uploadFileName;
    }

}
